/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package meteocal.control;

import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Inject;
import meteocal.entity.Event;
import meteocal.entity.Users;
import meteocal.entityManager.UserManager;
import meteocal.exception.PrivacyException;

/**
 *
 * @author andrea
 */
@Stateless
public class UserControl {
    
    @Inject 
    UserManager um;   
    
    /**
     * Retrieves all the events in the logged user's calendar.
     * @return the resulting list
     */
    public List<Event> loadCalendar(){
        List <Event> calendar = um.getCreatedEvents();
        calendar.addAll(um.getAcceptedEvents());
        return calendar;
    }
    
    /**
     * Retrieves all the public events in the given user's calendar. It may return 
     * an empty list if the given user has set his calendar visibility to 'private'.
     * @param user
     * @return the resulting list
     * @throws PrivacyException if the user's calendar is private.
     */
    public List<Event> loadCalendar(Users user) throws PrivacyException{
        List <Event> calendar = um.getCreatedEvents(user);
        calendar.addAll(um.getAcceptedEvents(user));
        return calendar;
    }    
    
    /**
     * Checks if there are any empty field that must be fulfilled.
     * @param user
     * @return true if there are no empty fields, false otherwise.
     */
    private boolean checkFields(Users user) {        
        String name = user.getName();
        String surname = user.getSurname();
        String pwd = user.getPassword();
        return name != null && surname != null && pwd != null;
    }
    
}
